package com.kotlin.android.router.interceptor

import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.callback.NavigationCallback
import com.alibaba.android.arouter.launcher.ARouter
import com.kotlin.android.ktx.ext.KEY_PATH
import com.kotlin.android.ktx.utils.LogUtils
import com.kotlin.android.router.path.RouterActivityPath

/**
 * 创建者: zl
 * 创建时间: 2020/6/8 5:23 PM
 * 描述:
 */
class LoginNavigationCallbackImpl : NavigationCallback {
    override fun onLost(postcard: Postcard?) {
        /**
         * 找不到要打开的activity
         */
        LogUtils.v("找不到要打开的activity ${postcard?.path}")
    }

    override fun onFound(postcard: Postcard?) {
        /**
         * 找到要打开的activity
         */
        LogUtils.v("找到要打开的activity ${postcard?.path}")
    }

    override fun onInterrupt(postcard: Postcard?) {
        /**
         * 找到了要打开的activity
         */
//        LogUtils.v("拦截要打开的activity ${postcard?.path}")
        val path = postcard?.path
//        LogUtils.e("path: $path")
        val bundle = postcard?.extras
//        LogUtils.e("bundle: $bundle")

        /**
         * 被登录拦截了下来了
         * 需要调转到登录页面，把参数跟被登录拦截下来的路径传递给登录页面，登录成功后再进行跳转被拦截的页面
         */
        ARouter.getInstance().build(RouterActivityPath.User.PAGER_LOGIN)
            .with(bundle)
            .withString(KEY_PATH, path)
            .navigation()

    }

    override fun onArrival(postcard: Postcard?) {
        /**
         * 已经打开了目标activity
         */
        LogUtils.v("已经打开了目标activity ${postcard?.path}")

    }
}